package com.jia.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jia.blog.entity.VideoType;
import com.jia.blog.entity.vo.VideoTypeVo;
import com.jia.blog.mapper.VideoTypeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jia.blog.service.VideoTypeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiajia
 * @since 2020-12-05
 */
@Service
public class VideoTypeServiceImpl extends ServiceImpl<VideoTypeMapper, VideoType> implements VideoTypeService {

    @Override
    public Map<String, Object> queryPageList(VideoTypeVo videoTypeVo) {

        Integer pageNum = videoTypeVo.getPageNum();
        Integer pageSize = videoTypeVo.getPageSize();
        String name = videoTypeVo.getName();
        Long cateId = videoTypeVo.getCateId();

        QueryWrapper<VideoType> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        if(!StringUtils.isEmpty(name)){
            wrapper.like("name",name);
        }

        if(!StringUtils.isEmpty(cateId)){
            wrapper.like("cate_id",cateId);
        }

        Page<VideoType> page = new Page<>(pageNum,pageSize);
        IPage<VideoType> videoTypeIPage = baseMapper.selectPage(page, wrapper);
        long total = videoTypeIPage.getTotal();
        long pages = videoTypeIPage.getPages();
        long size = videoTypeIPage.getSize();
        List<VideoType> records = videoTypeIPage.getRecords();

        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("pages",pages);
        map.put("size",size);
        map.put("records",records);
        return map;

    }
}
